const connection = require('../db/index')
const express = require("express");
const admin = express.Router();
//生成token信息
var jwt = require('jsonwebtoken');
//-------------------  信息------------密钥
var mes = jwt.sign({ foo: 'bar' }, 'lizibin');
//登录验证
admin.post('/user',function(req,res){
    // 获取登录信息
    connection.query('select * from admin', function(err, rows, fields) {
        if (err) {
            throw err
        }
        if(rows[0].user == req.body.username && rows[0].password == req.body.password){
            // 匹配成功
            res.send({
                token:mes,
                stats:200
            })
        }else{
            res.send({
                stats:400
            })
        }        
    })
})
module.exports = admin